package Class003;

//知识点：可以直接定义二进制数
//方法：int num = 0b.....
//知识点：十六进制数
//方法：int num = 0x.....
public class BinarySystem {
    public static void main(String[] args) {
        showBin(78);
        showBin(-1);
        showBin(-6);
        showBin(2147483647);
        showBin(0b1001110);
        showBin(0x4e);
        showBin(~0x4e + 1);
    }

    public static void showBin(int num) {
        System.out.println("num:" + num);
        System.out.println("binary:");
        printBinary(num,0);
        System.out.println();
        System.out.println("==================================");
    }

    public static void printBinary(int num, int counter) {
        if(counter == 32) return;
        printBinary(num >> 1, counter + 1);
        System.out.print(num & 1);
    }
}
